package prv.pursuivant.config.impl;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import prv.pursuivant.config.CategorySerializer;
import prv.pursuivant.core.AchievTypesTree;

import com.google.inject.Inject;
import com.thoughtworks.xstream.XStream;

public class XStreamCategorySerializer implements CategorySerializer {

	protected final XStream xstream;

	@Inject
	public XStreamCategorySerializer(XStream xstream) {
		this.xstream = xstream;
	}

	@Override
	public AchievTypesTree readTree(InputStream stream) throws IOException {
		Object fromXML = xstream.fromXML(stream);
		final AchievTypesTree tree = (AchievTypesTree) fromXML;
		return tree;
	}

	@Override
	public void writeTree(AchievTypesTree tree, OutputStream stream)
			throws IOException {
		xstream.toXML(tree, stream);
	}

}
